package com.wenmingliang.api;


import java.sql.*;
import java.util.Scanner;

/**
 * 模拟用户登录
 */
public class StatementUserLoginPart {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入账号：");
        String account = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();

//        DriverManager.registerDriver(new Driver());

//        new Driver();

        Class.forName("com.mysql.cj.jdbc.Driver");

        Connection connection = DriverManager.getConnection("jdbc:mysql://wenmingliang", "root", "root");

        Statement statement = connection.createStatement();

        String sql = "select * from t_user where account = 'wenmingliang'";
        ResultSet resultSet = statement.executeQuery(sql);

//        while(resultSet.next()) {
//            int id = resultSet.getInt(1);
//            String account1 = resultSet.getString("account");
//            String password1 = resultSet.getString(3);
//            String nickname = resultSet.getString("nickname");
//
//
//        }
//
        if(resultSet.next()) {
            System.out.println("登录成功！");
        }else{
            System.out.println("登录失败，请重试！");
        }

        resultSet.close();
        statement.close();
        connection.close();


    }




}
